public class HomeWork04_08{
    public static void main(String[] args){
        int i = 0;
        int test;
        do{
            ++i;
            test = i * 9 * 10 + 9;
        }while(!(test % 8 == 1 && test % 7 == 5));
        
        System.out.println(test);
    }
}